package com.lcz.mytest.fragment;

import android.support.v4.app.Fragment;

import java.util.HashMap;
import java.util.Map;

/*管理Fragment工厂类*/
public class FragmentFactory {

    private static Map<Integer, Fragment> mFragments = new HashMap<Integer, Fragment>();

    public static Fragment createFragment(int position) {
        Fragment fragment = null;
        fragment = mFragments.get(position); // 在集合中取出来Fragment
        if (fragment == null) { // 如果再集合中没有取出来 需要重新创建
            if (position == 0) {
                fragment = new SHAllFragment();//上海个股列表
            } else if (position == 1) {
                fragment = new SZAllFragment();//深圳个股列表
            } else if (position == 2) {
               // fragment = new CollectFragment();//收藏页面
            }
            if (fragment != null) {
                mFragments.put(position, fragment);// 把创建好的Fragment存放到集合中缓存起来
            }
        }
        return fragment;

    }
}
